package com.googlecode.moneyManager.web

/**
 * Created by sergiy.doroshenko
 * Date: 9/22/11 
 */
import java.sql.{DriverManager, ResultSet}
import util.ImplicitClose

object Person {

  import ImplicitClose._
  import java.sql._

  def findPeople(conn: Connection, q: String): List[Person] =
    using(conn.createStatement) {
      st =>
        using(st.executeQuery(q)) {
          rs =>
            bmap(rs.next) {
              new Person(rs.getString("user_name"), rs.getString("first_name"), rs.getString("last_name"))
            }
        }
    }
}

case class Person(user_name: String, fname: String, sname: String)


object ReadData{
  //classOf[oracle.jdbc.OracleDriver]
  def testPersons2(): List[Person] = {
    Class.forName("oracle.jdbc.driver.OracleDriver")
    val conn2 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","nordiconline","oracle")
    val persons = for (c <- Person.findPeople(conn2, "SELECT * FROM Person where user_name like '%test%'")) yield c
    persons
  }
}